package cn.edu.xmu.oomall.comment.dao.openfeign;

import cn.edu.xmu.oomall.comment.dao.CommentDao;
import cn.edu.xmu.oomall.comment.dao.bo.Comment;
import cn.edu.xmu.oomall.comment.dao.bo.OrderItem;
import cn.edu.xmu.oomall.comment.mapper.openfeign.OrderItemPoMapper;
import cn.edu.xmu.oomall.comment.mapper.po.OrderItemPo;
import lombok.RequiredArgsConstructor;
import cn.edu.xmu.javaee.core.util.CloneFactory;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @author 谢传艳
 * @date 2024/12/14
 */
@Repository
@RequiredArgsConstructor
public class OrderItemDao {
    private final OrderItemPoMapper orderItemPoMapper;
    private final CommentDao commentDao;

    /**
     * 更新订单明细
     * @param orderItem
     */
    public void save(OrderItem orderItem) {
        orderItemPoMapper.modifyOrderItem(orderItem.getId(), CloneFactory.copy(new OrderItemPo(), orderItem));
    }

    public OrderItem build(OrderItemPo po) {
        OrderItem orderItem = CloneFactory.copy(new OrderItem(), po);
        orderItem.setCommentDao(this.commentDao);
        orderItem.setOrderItemDao(this);
        return orderItem;
    }

    public OrderItem findById(Long id) {
        return this.build(this.orderItemPoMapper.findOrderItemById(id).getData());
    }

}
